package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.OrderDetailDao;
import dao.OrderItemDao;
import entity.Order;
import entity.OrderItem;
import service.OrderItemService;
import service.OrderService;


/**
 * Servlet implementation class MyOrderServlet
 */
@WebServlet("/MyOrderServlet")
public class MyOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		int id=Integer.valueOf(request.getParameter("id"));
		int id = Integer.parseInt((String) request.getSession().getAttribute("loginUserId"));
		request.getSession().setAttribute("id", id); //将用户ID设在session
		OrderService orderService=new OrderService(); //生成订单业务层对象
		List<Order> orders=new ArrayList<>(); //订单集合
		orders=orderService.getOrderById(id); //调用订单业务层
		request.getSession().setAttribute("orders", orders); //将全部订单集合存放在session
		request.getRequestDispatcher("MyOrder.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
